﻿using Paas.Core.Const.Enums.Common;
using Paas.Core.Sys.Entities;
using Basefr.Attributes;
using Basefr.Core.Entities;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Paas.Core.Common.Entities
{
    /// <summary>
    /// 文件
    /// </summary>
    [MainTable(nameof(File))]
    public class File : EntityBase
    {
        /// <summary>
        /// 文件类型
        /// </summary>
        public EnumFileType Type { get; set; }

        /// <summary>
        /// 文件名
        /// </summary>
        [Required]
        [MaxLength(500)]
        public string Name { get; set; }

        /// <summary>
        /// 文件MIME类型
        /// </summary>
        [Required]
        [MaxLength(100)]
        public string MimeType { get; set; }

        /// <summary>
        /// 随机编码
        /// </summary>
        [Required]
        [MaxLength(100)]
        public string Code { get; set; }

        /// <summary>
        /// 物理路径
        /// </summary>
        [MaxLength(1000)]
        public string PhysicalPath { get; set; }

        /// <summary>
        /// 实际保存的文件名（GUID）
        /// </summary>
        [Required]
        [MaxLength(200)]
        public string PhysicalName { get; set; }

        /// <summary>
        /// 文件大小
        /// </summary>
        public long Size { get; set; }

        /// <summary>
        /// 是否系统创建（否：用户上传）
        /// </summary>
        public bool IsSys { get; set; }

        /// <summary>
        /// 上传者
        /// </summary>
        public long? UploaderId { get; set; }
        [ForeignKey(nameof(UploaderId))]
        public virtual User Uploader { get; set; }


        public string FullFileName => System.IO.Path.Combine(PhysicalPath, PhysicalName);

    }
}

